package com.wang.springboot04webrestfulcrud.component;

import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

@Component
public class MyErrorAttributes extends DefaultErrorAttributes{
    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        Map<String, Object> map = super.getErrorAttributes(webRequest, includeStackTrace);
        //往map中加入出现自定义异常的现实数据
        map.put("ext",webRequest.getAttribute("ext",0));
        //在自定义的errrorattribute中加入数据
        map.put("company","wangzechen");
        return map;
    }
}
